package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.CustomerReturnListGoods;
import com.atguigu.jxc.service.CustomerReturnListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("customerReturnListGoods")
public class CustomerReturnListController {
    @Autowired
    private CustomerReturnListService customerReturnListService;

    //2.1、客户退货单保存  并保存对应退货商品
    @PostMapping("save")
    public ServiceVO saveCustomerReturnListAndGoods(CustomerReturnList customerReturnList, String customerReturnListGoodsStr, HttpServletRequest request){
        String returnNumber = request.getParameter("returnNumber");
        ServiceVO serviceVO = customerReturnListService.saveCustomerReturnListAndGoods(customerReturnList,customerReturnListGoodsStr,returnNumber);
        return serviceVO;
    }
    //4.1、客户退货单查询（可查询条件：退货单号、客户、退款状态）
    @PostMapping("list")
    public Map<String,Object> getCustomerReturnList(String returnNumber, Integer customerId, Integer state, String sTime,String eTime){
        List<CustomerReturnList> list = customerReturnListService.getCustomerReturnList(returnNumber,customerId,state,sTime,eTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }
    //4.2、退货单商品信息
    @PostMapping("goodsList")
    public Map<String,Object> getCustomerReturnListGoodsList(Integer customerReturnListId){
        List<CustomerReturnListGoods> list = customerReturnListService.getCustomerReturnListGoodsList(customerReturnListId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }
    //4.3、删除退货单
    @PostMapping("delete")
    public ServiceVO deleteCustomerReturnListAndGoods(Integer customerReturnListId){
        ServiceVO serviceVO = customerReturnListService.deleteCustomerReturnListAndGoods(customerReturnListId);
        return serviceVO;
    }
    //4.2、客户退货统计（可根据 商品类别、商品编码或名称 条件查询）
    @PostMapping("count")
    public String countCustomerReturnListGoods(String sTime, String eTime, Integer goodsTypeId, String codeOrName){
        String jsonStr = customerReturnListService.countCustomerReturnListGoods(sTime,eTime,goodsTypeId,codeOrName);
        return jsonStr;
    }
    //http://localhost:8080/customerReturnListGoods/updateState
    //customerReturnListId: 7  ServiceVO
    //客户统计 退货单 支付结算
    @PostMapping("updateState")
    public ServiceVO updateStateCustomerReturnList(String customerReturnListId){
        ServiceVO serviceVO = customerReturnListService.updateStateCustomerReturnList(customerReturnListId);
        return serviceVO;
    }
}
